package com.yunshu.yunshuapp.xianhuo;

import android.content.Intent;
import android.support.v4.widget.SwipeRefreshLayout;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.yunshu.yunshuapp.NavigationBar;
import com.yunshu.yunshuapp.OnTapListener;
import com.yunshu.yunshuapp.R;
import com.yunshu.yunshuapp.kuaixun.KuaixunChannel;
import com.yunshu.yunshuapp.kuaixun.TypeListAdapter;
import com.yunshu.yunshuapp.network.YSRequest;

import java.util.ArrayList;

public class CityChooseActivity extends AppCompatActivity implements OnTapListener {

    public static final int REQUEST_CODE = 10002;

    private ArrayList<KuaixunChannel> models;
    private SwipeRefreshLayout swipeRefreshLayout;
    private RecyclerView mRecyclerView;
    private TypeListAdapter mCityAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_city_choose);

        NavigationBar navi = (NavigationBar)findViewById(R.id.navigationBar);
        navi.setTitle("频道定制");
        navi.putInActivity(this);

        addList();
    }

    private void addList() {
        mRecyclerView = (RecyclerView) findViewById(R.id.list_view);
        // use a linear layout manager
        LinearLayoutManager mLayoutManager = new LinearLayoutManager(this);
        //设置RecycleView的显示方向：（默认为垂直） 水平
        mLayoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        mRecyclerView.setLayoutManager(mLayoutManager);
        mRecyclerView.setHasFixedSize(true);

        String[] cities = new String[]{"全部","北京市","天津市","河北省","山西省","内蒙古自治区","辽宁省","吉林省","黑龙江省","上海市","江苏省","浙江省","安徽省","福建省","江西省","山东省","河南省","湖北省","湖南省","广东省","广西壮族自治区","海南省","四川省","贵州省","云南省","重庆市","西藏自治区","陕西省","甘肃省","青海省","宁夏回族自治区","新疆维吾尔自治区","香港特别行政区","澳门特别行政区","台湾省"};
        ArrayList<KuaixunChannel> cityList = new ArrayList<KuaixunChannel>();
        for (String city : cities){
            KuaixunChannel newCity = new KuaixunChannel();
            newCity.setTitle(city);
            newCity.setChannelId(city);
            cityList.add(newCity);
        }
        mCityAdapter = new TypeListAdapter(getBaseContext());
        mCityAdapter.activity = this;
        mCityAdapter.setModels(cityList);
        mCityAdapter.tapListener =this;
        mRecyclerView.setAdapter(mCityAdapter);

    }

    @Override
    public void onSingleTap(View v, int position) {
        Intent mIntent = new Intent();
        KuaixunChannel newCity = mCityAdapter.getModels().get(position);

        mIntent.putExtra("data", newCity.getTitle());

        this.setResult(RESULT_OK,mIntent);
        this.finish();
    }
}
